import React, { Component } from 'react';
import { Link, routerRedux } from 'dva/router';
import { connect } from 'dva';

import { List, InputItem, Button, Toast, Flex,Icon,Tabs,WingBlank } from 'antd-mobile';
import { createForm } from 'rc-form';
import NavTopBar from '../../components/NavTopBar/NavTopBar';
import MyScroll from '../../components/MyScroll/MyScroll';
import weixinsvg from '../../assets/img/weixin.svg';
import weibosvg from '../../assets/img/weibo.svg';
import qqsvg from '../../assets/img/QQ.svg';
import { apiURl } from '../../utils/common';
//import { common } from 'common';

const { Item } = List;


class MemberPwd extends Component {
    constructor(props) {
        super(props);
        this.state={
        phone:this.props.match.params.data
        }

    }

    onSubmit = () => {
        const { oldPwd,newPwd,newPwd1 } = this.props.form.getFieldsValue();
        if (!newPwd) {
            Toast.info('请输入新密码', 1.5);
            return;
        }
        if (!newPwd1) {
            Toast.info('请输入确认新密码', 1.5);
            return;
        }
        if (newPwd1!=newPwd) {
            Toast.info('两次密码不一致', 1.5);
            return;
        }

        this.props.dispatch({ type: 'login/mobileVerifyEFF', obj: { telphone:this.props.match.params.data, newPwd:newPwd ,verifyCode:this.props.match.params.Data} }).then((r)=>{
            if (r.code == 200) {
                Toast.success(r.msg, 1.5, ()=>{
                    this.props.dispatch(routerRedux.replace({
                        pathname: '/login',
                    }))
                });
            } else {
                Toast.fail(r.msg, 1.5);
            }
        });

    }
    render() {
        const { getFieldProps, getFieldError } = this.props.form;
        console.log(this.props)
        return (
            <Flex style={{
                height:"100%"
            }} direction="column"

            >
                <NavTopBar title="修改密码" dispatch={this.props.dispatch}/>
                    <form style={{width:"100%"}}>
                                <List
                                    renderFooter={() => getFieldError('username') && getFieldError('username').join(',')}
                                >

                                    <InputItem {...getFieldProps('newPwd')} placeholder="请输入新密码" type="password" >新密码</InputItem>
                                    <InputItem {...getFieldProps('newPwd1')} placeholder="确认新密码" type="password" >确认新密码</InputItem>

                                    <Item style={{ backgroundColor: 'unset', marginTop: '.3rem' }}>
                                        <Button type="primary" onClick={this.onSubmit} style={{borderRadius:".5rem"}}>修改</Button>
                                    </Item>

                                </List>
                    </form>


            </Flex>
        );
    }
}

export default connect(({ login }) => ({ login }))(createForm()(MemberPwd));